home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 391 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: solon.com!not-for-mail
  2. From: Dominic Feeley <dom@dfdesign.demon.co.uk>
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion.
  5. Date: 14 Feb 1996 21:25:15 -0600
  6. Organization: DF Designs
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4fu92r$9so@solutions.solon.com>
  10. References: <4fstj7$2l6@solutions.solon.com>
  11. Reply-To: dom@dfdesign.demon.co.uk
  12. NNTP-Posting-Host: solutions.solon.com
  13. X-NNTP-Posting-Host: dfdesign.demon.co.uk
  14. X-Newsreader: Demon Internet Simple News v1.30
  15. X-Mail2News-Path: dfdesign.demon.co.uk
  16.  
  17. In article <4fstj7$2l6@solutions.solon.com>
  18.            rune.huseby@gpi.telemax.no "Rune Huseby" writes:
  19.  
  20. > I got a problem understanding the rules on integral promotion in
  21. > the C language:
  22. >
  23. > short test(short x1, short x2);
  24. >
  25. > My compiler (Microsoft Visual C++ 4.0), automagically converts
  26. > my short-parameters to int's, even though all variables involved
  27. > are short. I know that the standard says that all arguments can
  28. > be converted to the biggest 'type' of all the arguments, but is
  29. > it correct that char's and short's always are promoted to int's,
  30. > without regard to the other arguments in the expression?
  31.  
  32. This is news to me, but it seems that section 6.2.1.5 of the standard
  33. says that the lowest integer type is an int. If I am going to buy these
  34. things I suppose I ought to read them.
  35.  
  36. My reading is that
  37. short result = x1 + x2; /* going from int to short, possible loss of data */
  38.  
  39. gives the "same" result mathematically as
  40. short result = ( int ) x1 + ( int ) x2 ;
  41. i.e. you assign an int to a short value. The results of this conversion
  42. are ( I think ) implementation-defined if the short is signed.
  43.  
  44. Regards,
  45. Dominic.
  46.  
  47. --
  48. Dominic Feeley
  49.